﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using SmartRoute.Data;

namespace SmartRoute.Data.ViewModels
{
    public class LocationViewModel: INotifyPropertyChanged
    {
        #region Fields

        protected Location _location;

        #endregion

        #region Properties

        public double Latitude
        {
            get{return _location.Latitude;}
            set
            {
                if (value != _location.Latitude)
                {
                    _location = _location.changeLatitude(value);
                    Notify("Latitude");
                }
            }
        }

        public double Longitude
        {
            get{return _location.Longitude;}
            set
            {
                if (value != _location.Longitude)
                {
                    _location = _location.changeLongitude(value);
                    Notify("Longitude");
                }
            }
        }

        public string Address
        {
            get{return _location.Address;}
            set
            {
                if (value != _location.Address)
                {
                    _location.Address = value;
                    Notify("Address");
                }
            }
        }

        public Location Location
        {
            get { return _location; }
            set
            {
                if (value != _location)
                {
                    _location = value;
                    Notify("Location");
                }
                else if (value.Address != _location.Address)
                {
                    this.Address = value.Address;
                }
            }
        }

        #endregion

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        protected void Notify(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        public LocationViewModel(Location location)
        {
            _location = location;
        }
    }
}
